package com.honeyms.project.blog.blogfavoritesusercontent.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.honeyms.framework.aspectj.lang.annotation.Log;
import com.honeyms.framework.aspectj.lang.enums.BusinessType;
import com.honeyms.project.blog.blogfavoritesusercontent.domain.BlogFavoritesUserContent;
import com.honeyms.project.blog.blogfavoritesusercontent.service.IBlogFavoritesUserContentService;
import com.honeyms.framework.web.controller.BaseController;
import com.honeyms.framework.web.domain.AjaxResult;
import com.honeyms.common.utils.poi.ExcelUtil;
import com.honeyms.framework.web.page.TableDataInfo;

/**
 * 用户收藏帖子Controller
 * 
 * @author honeyms
 * @date 2020-10-16
 */
@Controller
@RequestMapping("/blog/blogfavoritesusercontent")
public class BlogFavoritesUserContentController extends BaseController
{
    private String prefix = "blog/blogfavoritesusercontent";

    @Autowired
    private IBlogFavoritesUserContentService blogFavoritesUserContentService;

    @RequiresPermissions("blog:blogfavoritesusercontent:view")
    @GetMapping()
    public String blogfavoritesusercontent()
    {
        return prefix + "/blogfavoritesusercontent";
    }

    /**
     * 查询用户收藏帖子列表
     */
    @RequiresPermissions("blog:blogfavoritesusercontent:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BlogFavoritesUserContent blogFavoritesUserContent)
    {
        startPage();
        List<BlogFavoritesUserContent> list = blogFavoritesUserContentService.selectBlogFavoritesUserContentList(blogFavoritesUserContent);
        return getDataTable(list);
    }

    /**
     * 导出用户收藏帖子列表
     */
    @RequiresPermissions("blog:blogfavoritesusercontent:export")
    @Log(title = "用户收藏帖子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BlogFavoritesUserContent blogFavoritesUserContent)
    {
        List<BlogFavoritesUserContent> list = blogFavoritesUserContentService.selectBlogFavoritesUserContentList(blogFavoritesUserContent);
        ExcelUtil<BlogFavoritesUserContent> util = new ExcelUtil<BlogFavoritesUserContent>(BlogFavoritesUserContent.class);
        return util.exportExcel(list, "blogfavoritesusercontent");
    }

    /**
     * 新增用户收藏帖子
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户收藏帖子
     */
    @RequiresPermissions("blog:blogfavoritesusercontent:add")
    @Log(title = "用户收藏帖子", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BlogFavoritesUserContent blogFavoritesUserContent)
    {
        return toAjax(blogFavoritesUserContentService.insertBlogFavoritesUserContent(blogFavoritesUserContent));
    }

    /**
     * 修改用户收藏帖子
     */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        BlogFavoritesUserContent blogFavoritesUserContent = blogFavoritesUserContentService.selectBlogFavoritesUserContentById(userId);
        mmap.put("blogFavoritesUserContent", blogFavoritesUserContent);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户收藏帖子
     */
    @RequiresPermissions("blog:blogfavoritesusercontent:edit")
    @Log(title = "用户收藏帖子", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BlogFavoritesUserContent blogFavoritesUserContent)
    {
        return toAjax(blogFavoritesUserContentService.updateBlogFavoritesUserContent(blogFavoritesUserContent));
    }

    /**
     * 删除用户收藏帖子
     */
    @RequiresPermissions("blog:blogfavoritesusercontent:remove")
    @Log(title = "用户收藏帖子", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(blogFavoritesUserContentService.deleteBlogFavoritesUserContentByIds(ids));
    }
}
